home *** CD-ROM | disk | FTP | other *** search
- Path: prairienet.org!sjmccaug
- From: sjmccaug@prairienet.org (Scott J. McCaughrin)
- Newsgroups: comp.lang.c++
- Subject: Re: Q:order of evaluation
- Date: 23 Jan 1996 10:58:12 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4e2f04$bnp@vixen.cso.uiuc.edu>
- References: <4dfhlu$a33$1@mhafn.production.compuserve.com>
- Reply-To: sjmccaug@prairienet.org (Scott J. McCaughrin)
- NNTP-Posting-Host: firefly.prairienet.org
-
-
- In a previous article, 100336.3326@CompuServe.COM (Holger Maier) says:
-
- >Consider
- >#include <iostream>
- >int main() {
- > int i=1;int j=i+(i+=1);
- > cout<<i<<','<<j<<'\n';
- > return 0;
- >}
- >on my compiler this produces 2,4
- >Looked up the ARM:
- >5: .. The order of evaluation of subexpressions is determined by the
- >precedence and grouping of operators.
- >5.7: The additive operators + and - group left to right.
- >So, j should be assigned 3 ??
-
- Hi, Holger:
-
- No, it appears that the compiler is correct. The parentheses override
- any other precedence rules, so (i+=1) is executed first to set i == 2,
- then the assignment has the effect of assigning i' + 2 (= 2 + 2) to j.
-
- -- Scott McC.
-
-